home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / gsdbloo.exe / DEMOB004.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-24  |  3KB  |  92 lines

  1. program DemoB004;
  2. {------------------------------------------------------------------------------
  3.                               DBase File Lister
  4.                                    Sample 4
  5.                                  Demo Program
  6.  
  7.        Copyright (c)  Richard F. Griffin
  8.  
  9.        10 February 1992
  10.  
  11.        102 Molded Stone Pl
  12.        Warner Robins, GA  31088
  13.  
  14.        -------------------------------------------------------------
  15.        This program demonstrates how dBase fields may be modified using
  16.        Griffin Solutions units.
  17.  
  18.        If the DEMOB1.DBF file does not exist, the program will display a
  19.        a message that the file was not found and to run DEMOB001 to make
  20.        the file.
  21.  
  22.        The program initializes a dBase file object, opens the file, and
  23.        proceeds to list selected fields from each record.
  24.  
  25.        It will reverse all the letters in LASTNAME and write the record
  26.        back to disk.
  27.  
  28.        Finally, it will read the file back in, list the new values, put
  29.        the old LASTNAME back to the record by reversing letters again, and
  30.        writing the record again.
  31.  
  32. -------------------------------------------------------------------------------}
  33.  
  34. uses
  35.    CRT,
  36.    DOS,
  37.    GS_Date,
  38.    GS_dBase,
  39.    GS_DBFld,
  40.    GS_FileH;
  41. var
  42.    MyFile  : GS_dBFld_Objt;
  43.    ftest   : file;
  44.    i       : integer;
  45.    s1,
  46.    s2      : string[30];
  47.    c       : char;
  48.  
  49. procedure WorkTheFile;            {reads the file, displays fields, and }
  50.                                   {reverses LASTNAME                    }
  51. begin
  52.    MyFile.GetRec(Top_Record);     {Get the first record in the file}
  53.    while not MyFile.File_EOF do   {Repeat until end-of-file}
  54.    begin
  55.       s1 := MyFile.StringGet('LASTNAME');
  56.       writeln(s1,', ',
  57.               MyFile.StringGet('FIRSTNAME'));
  58.       s2 := '';
  59.       for i := 1 to length(s1) do s2 := s1[i] + s2;
  60.       Myfile.StringPut('LASTNAME',s2);
  61.       MyFile.PutRec(MyFile.RecNumber);
  62.       MyFile.GetRec(Next_Record); {Get the next sequential record}
  63.    end;
  64. end;
  65.  
  66.  
  67. {------ Main Routine ------}
  68.  
  69. begin
  70.    ClrScr;
  71.    if not GS_FileExists(ftest, 'DEMOB1.DBF') then
  72.    begin
  73.       writeln('File DEMOB1.DBF not found.  Run DEMOB001 to create.');
  74.       halt;
  75.    end;
  76.                        {The 'Real' example starts here}
  77.  
  78.    MyFile.Init('DEMOB1');          {Initialize object using the dBase III}
  79.                                   {file DEMOB1.  DBF Extension assumed}
  80.    MyFile.Open;                   {Open the object's file}
  81.    WorkTheFile;
  82.    writeln('------ Now to show LASTNAME is reversed in the file:');
  83.    write('Press any Key to continue:');
  84.    c := ReadKey;
  85.    writeln;
  86.    WorkTheFile;
  87.    MyFile.Close;
  88.    writeln('------ OK, the file is back in shape now');
  89.    write('Press any Key to continue:');
  90.    c := ReadKey;
  91. end.
  92.